<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script src='https://cdn.staticfile.org/react/16.4.0/umd/react.development.js'></script>
    <script src='https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js'></script>
    <!-- 生产环境中不建议使用 -->
    <script src='https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js'></script>
    <!-- PropTypes文件 -->
    <script src='https://unpkg.com/prop-types@15.6.2/prop-types.js'></script>
</head>

<body>
    <div id='app'>
    </div>
    <script type='text/babel'>
        class Demo extends React.Component{
            showData1 = ()=>{
                console.log(this.input1.value)
            }

            showData2 = ()=>{
                console.log(this.input2.value)
            }

            render(){
                /*
                    回调函数形式的ref也很简单，只需要把ref的值写成一个回调箭头函数，react渲染时发现ref里面是个回调函数，则帮我们去调用，由于箭头函数没有this，所以就找上级也就是render的函数作用域，很明显，类式组件是react先创建一个实例再执行render的，所以this也就指向了组件实例。所以本案例中就是把两个ref实例直接放到了组件实例上，不再通过this.refs读取                     
                */
                return (
                    <div>
                        <input type="text" ref={node=>this.input1 = node}/>
                        <button onClick={this.showData1}>点我提示左侧输入框信息</button>
                        <input type="text" ref={node=>this.input2 = node} onBlur={this.showData2}/>    
                    </div>
                )
            }
        }

        ReactDOM.render(<Demo/>,document.getElementById('app'))
    </script>
</body>

</html>